CC		= arm-linux-gcc
LD 		= arm-none-linux-gnueabi-ld
OBJCOPY	= arm-none-linux-gnueabi-objcopy
OBJDUMP	= arm-none-linux-gnueabi-objdump
AR		= arm-none-linux-gnueabi-ar

TARGET		  	?= bsp

INCDIRS 		:= 	$(shell pwd)\
					driver \
					driver/inc\
				   	include \
				   	lib
				    
				   			   
SRCDIRS			:= 	project\
					driver/src \
					driver

INCLUDE			:= $(patsubst %, -I %, $(INCDIRS))

SFILES			:= $(foreach dir, $(SRCDIRS), $(wildcard $(dir)/*.S))
CFILES			:= $(foreach dir, $(SRCDIRS), $(wildcard $(dir)/*.c))

SFILENDIR		:= $(notdir  $(SFILES))
CFILENDIR		:= $(notdir  $(CFILES))

SOBJS			:= $(patsubst %, obj/%, $(SFILENDIR:.S=.o))
COBJS			:= $(patsubst %, obj/%, $(CFILENDIR:.c=.o))
OBJS			:= $(SOBJS) $(COBJS)



VPATH			:= $(SRCDIRS)

.PHONY: clean

$(TARGET).bin : $(OBJS)
	$(LD) -Ttext 0x0 -o $(TARGET).elf $^
	$(OBJCOPY) -O binary -S $(TARGET).elf $@
	$(OBJDUMP) -D -m arm $(TARGET).elf > $(TARGET).dis
	gcc app/mkv210_image.c -o app/mkx210
	app/mkx210 $(TARGET).bin $(TARGET)_sd.bin

$(SOBJS) : obj/%.o : %.S
	$(CC) -Wall -nostdlib -c -O2  $(INCLUDE) -o $@ $<

$(COBJS) : obj/%.o : %.c
	$(CC) -Wall -nostdlib -c -O2  $(INCLUDE) -o $@ $<

clean:
	rm -rf $(TARGET).elf $(TARGET).dis $(TARGET).bin $(COBJS) $(SOBJS)
